package com.xieyong.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Leetcode2210 {


    public static void main(String[] args) {
        Leetcode2210 leetcode = new Leetcode2210();
        int[] nums = {};
        int i = leetcode.countHillValley(nums);
        System.out.println(i);
    }


    public int countHillValley(int[] nums) {
        int res = 0;
        List<Integer> list = new ArrayList<>();
        list.add(nums[0]);
        for (int i = 1; i < nums.length; i++) {
            if (!(nums[i] == list.get(list.size() - 1))) {
                list.add(nums[i]);
            }
        }
        for (int i = 1; i < list.size() - 1; i++) {
            if (list.get(i) > list.get(i - 1) && list.get(i) > list.get(i + 1)) {
                res ++;
            } else if (list.get(i) < list.get(i - 1) && list.get(i) < list.get(i + 1)) {
                res ++;
            }
        }
        return res;
    }

}
